<template>
	<view>
		<view class="list">
			<view class="list-title">
				<view class="time-title">
					时间
				</view>
				<view class="password-title">
					密码
				</view>
				<view class="cope-title">
					操作
				</view>
			</view>
			<view class="list-value" v-for="(result, index) in resultList">
				<view class="list-value-single">
					<view class="time omit">
						{{result.gmtCreateStr}}
					</view>
					<view class="password omit">
						{{result.password}}
					</view>
					<view class="cope omit" @click="cope(result.password)">
						一键复制
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var _self

	export default {
		data() {
			return {
				resultList: []
			}
		},
		onLoad() {

			_self = this

			this.Init()

		},
		onPullDownRefresh() {
			this.Init()
			uni.stopPullDownRefresh()
		},
		methods: {
			Init() {
				var userInfo = this.getUser("userInfo")
				if (userInfo) {
					this.getList(userInfo)
				} else {
					uni.hideLoading()
					uni.showModal({
						title: '提示',
						content: '点击确认前往qq登录',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								uni.login({
									provider: 'qq',
									success(loginRes) {

										// 获取用户信息
										uni.getUserInfo({
											provider: "qq",
											success(info) {
												console.log(JSON.stringify(info))
												console.log(JSON.stringify(info.userInfo))
												uni.setStorageSync("userInfo", info.userInfo)
												_self.getList(info.userInfo)
											}
										})

									}
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				}
			},
			getList(userInfo) {
				uni.showLoading({
					title: '查询中...',
					mask: false
				})
				uni.request({
					url: _self.basicUrl + "user/search",
					method: "POST",
					data: {
						"openId": userInfo.openId
					},
					success: function(res) {
						if (res.data.code === 20000) {
							_self.resultList = res.data.data
						} else {
							// console.log(res.data.data)
							uni.showModal({
								content: JSON.stringify(res),
								showCancel: false
							});
						}
					},
					fail: (err) => {
						uni.showModal({
							content: err,
							showCancel: false
						});
					},
					complete() {
						// 停止当前页面下拉刷新
						uni.hideLoading()
						uni.stopPullDownRefresh()
					}
				})
			},
			//一键复制
			cope(password) {
				uni.setClipboardData({
				    data: password,
				    success: function () {
				        uni.showToast({
				        	title:"复制成功",
							mask:false
				        })
				    }
				});
			}
		},
		computed: {
			
		}
	}
</script>

<style>
	.list {
		margin: 0 20rpx;
	}

	.list-title {
		display: flex;
		flex-direction: row;
		margin: 30rpx 0;
		/* justify-content: space-around; */
		text-align: center;
	}

	.time-title {
		flex: 5
	}
	
	.password-title {
		flex: 5
	}

	.paste-title {
		flex: 2;
	}

	.list-value {
		/* display: flex;
		flex-direction: column; */
	}

	.list-value-single {
		display: flex;
		flex-direction: row;
		margin: 30rpx 0;
		/* justify-content: space-around; */
		background-color: #d2d4d2;
		height: 100rpx;
		line-height: 100rpx;
		font-size: 12px;
		text-align: center;
	}
	
	.time {
		flex: 5;
	}
	
	.password {
		flex: 5
	}
	
	.cope {
		flex: 2;
		color: #ff5500;
		line-height: 100rpx;
	}
	
</style>
